package cn.iocoder.yudao.module.handguard.service.userbasetable14;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.handguard.controller.app.userbasetable14.vo.*;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable14.UserBaseTable14DO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.handguard.convert.userbasetable14.UserBaseTable14Convert;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable14.UserBaseTable14Mapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.handguard.enums.ErrorCodeConstants.*;

/**
 * 住宅按揭贷款 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class UserBaseTable14ServiceImpl implements UserBaseTable14Service {

    @Resource
    private UserBaseTable14Mapper userBaseTable14Mapper;

    @Override
    public Long createUserBaseTable14(UserBaseTable14CreateReqVO createReqVO) {
        // 插入
        UserBaseTable14DO userBaseTable14 = UserBaseTable14Convert.INSTANCE.convert(createReqVO);
        userBaseTable14Mapper.insert(userBaseTable14);
        // 返回
        return userBaseTable14.getId();
    }

    @Override
    public void updateUserBaseTable14(UserBaseTable14UpdateReqVO updateReqVO) {
        // 校验存在
        validateUserBaseTable14Exists(updateReqVO.getId());
        // 更新
        UserBaseTable14DO updateObj = UserBaseTable14Convert.INSTANCE.convert(updateReqVO);
        userBaseTable14Mapper.updateById(updateObj);
    }

    @Override
    public void deleteUserBaseTable14(Long id) {
        // 校验存在
        validateUserBaseTable14Exists(id);
        // 删除
        userBaseTable14Mapper.deleteById(id);
    }

    private void validateUserBaseTable14Exists(Long id) {
        if (userBaseTable14Mapper.selectById(id) == null) {
            throw exception(USER_BASE_TABLE14_NOT_EXISTS);
        }
    }

    @Override
    public UserBaseTable14DO getUserBaseTable14(Long id) {
        return userBaseTable14Mapper.selectById(id);
    }

    @Override
    public List<UserBaseTable14DO> getUserBaseTable14List(Long userId) {
        LambdaQueryWrapper<UserBaseTable14DO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserBaseTable14DO::getUserId,userId);
        return userBaseTable14Mapper.selectList(queryWrapper);
    }

    @Override
    public PageResult<UserBaseTable14DO> getUserBaseTable14Page(UserBaseTable14PageReqVO pageReqVO) {
        return userBaseTable14Mapper.selectPage(pageReqVO);
    }

    @Override
    public List<UserBaseTable14DO> getUserBaseTable14List(UserBaseTable14ExportReqVO exportReqVO) {
        return userBaseTable14Mapper.selectList(exportReqVO);
    }

}
